package com.zygh.policeasset.controller;

import cn.hutool.core.util.StrUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.mapper.WitsmallMapper;
import com.zygh.policeasset.pojo.Witsmall;
import com.zygh.policeasset.service.WitsmallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/witsmall"})
@Api(tags = {"资产小类管理"}, description = "WitsmallController")
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/WitsmallController.class */
public class WitsmallController {
    @Autowired
    WitsmallService witsmallService;
    @Autowired
    WitsmallMapper witsmallMapper;

    @RequestMapping(value = {"/findall"}, method = {RequestMethod.GET})
    @ApiOperation("获取全部资产小类列表")
    public Object findAll(@RequestParam(value = "type", required = false) String type) {
        return this.witsmallService.findAll(type);
    }

    @RequestMapping(value = {"/listfindall"}, method = {RequestMethod.GET})
    @ApiOperation("获取全部资产小类分页列表")
    public Object listFindByBid(@RequestParam(value = "witbigNum", required = false) String witbigNum, @RequestParam(value = "type", required = false) String type, @RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        return this.witsmallService.listFindByBid(witbigNum, type, pageNum, pageSize);
    }

    @RequestMapping(value = {"/findById"}, method = {RequestMethod.GET})
    @ApiOperation("根据id查询")
    public Object findById(@RequestParam(value = "id", required = true) Integer id) {
        return this.witsmallService.findById(id);
    }

    @RequestMapping(value = {"/findbybid"}, method = {RequestMethod.GET})
    @ApiOperation("获取全部资产小类列表")
    public Object findByBid(@RequestParam(value = "witbigNum", required = false) String witbigNum, @RequestParam(value = "type", required = false) String type) {
        return this.witsmallService.findByBid(witbigNum, type);
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加资产小类")
    public Object add(@RequestBody Witsmall params) {
        if (StrUtil.isEmpty(String.valueOf(params.getWitbigNum()))) {
            return new CommonResult().validateFailed("资产大类不能为空");
        }
        if (StrUtil.isEmpty(params.getWitsmallName())) {
            return new CommonResult().validateFailed("名称不能为空");
        }
        if (this.witsmallMapper.findByName(params.getType(), params.getWitbigNum(), params.getWitsmallName()).intValue() > 0) {
            return new CommonResult().validateFailed("资产小类名称已存在，请核对");
        }
        if (this.witsmallService.add(params).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加错误");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改资产小类")
    public Object update(@RequestBody Witsmall params) {
        if (StrUtil.isEmpty(params.getWitsmallName())) {
            return new CommonResult().validateFailed("名称不能为空");
        }
        if (this.witsmallMapper.findByName(params.getType(), params.getWitbigNum(), params.getWitsmallName()).intValue() > 0) {
            return new CommonResult().validateFailed("资产小类名称已存在，请核对");
        }
        if (this.witsmallService.update(params).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改错误");
    }

    @RequestMapping(value = {"/remove"}, method = {RequestMethod.GET})
    @ApiOperation("删除资产小类")
    public Object remove(@RequestParam int id) {
        if (StrUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("id不能为空");
        }
        if (this.witsmallService.remove(id).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除错误");
    }

    @RequestMapping(value = {"/findDepreciation"}, method = {RequestMethod.GET})
    @ApiOperation("根据资产大类小类和类型查询折旧年限")
    public Object findDepreciation(@RequestParam(value = "type", required = false) String type, @RequestParam(value = "witbigNum", required = false) String witbigNum, @RequestParam(value = "witsmallNum", required = false) String witsmallNum) {
        return this.witsmallService.findDepreciation(type, witbigNum, witsmallNum);
    }
}